home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jbindentry.tcl < prev    next >
Encoding:
Text File  |  1995-02-09  |  4.7 KB  |  149 lines

  1. # jbindentry.tcl - support for Entry bindings
  2. # Copyright 1992-1994 by Jay Sekora.  All rights reserved, except 
  3. # that this file may be freely redistributed in whole or in part 
  4. # for non-profit, noncommercial use.
  5.  
  6. ######################################################################
  7. # j:selection_if_any - return selection if it exists, else {}
  8. #   this is from kjx@comp.vuw.ac.nz (R. James Noble)
  9. #   defined elsewhere, but copied here so the bindings libraries
  10. #   don't depend on jtkutils
  11. ######################################################################
  12.  
  13. if {[info procs j:selection_if_any] == {}} {
  14.   proc j:selection_if_any {} {
  15.     if {[catch {selection get} s]} {return ""} {return $s}
  16.   }
  17. }
  18.  
  19. ######################################################################
  20. # j:eb:init - initialise info for bindings
  21. ######################################################################
  22.  
  23. proc j:eb:init { {e Entry} } {
  24.   global J_PREFS env
  25.   if {! [info exists J_PREFS(typeover)]} {set J_PREFS(typeover) 1}
  26.   switch -exact $J_PREFS(bindings) {
  27.     basic {
  28.       j:eb:basic_init $e
  29.     }
  30.     emacs {
  31.       j:eb:emacs_init $e
  32.     }
  33.     edt {
  34.       j:eb:edt_init $e
  35.     }
  36.     vi {
  37.       j:eb:vi_init $e
  38.     }
  39.   }
  40.  
  41.   # read in user's supplementary entry bindings
  42.   j:source_config entrybindings.tcl
  43. }
  44.  
  45. ######################################################################
  46. # j:eb:no_op - do nothing
  47. ######################################################################
  48.  
  49. proc j:eb:no_op { args } {
  50.   return 0
  51. }
  52.  
  53. ######################################################################
  54. # j:eb:beep W - beep
  55. ######################################################################
  56.  
  57. proc j:eb:beep { W args } {
  58.   j:beep $W
  59.   return 0
  60. }
  61.  
  62. ######################################################################
  63. # j:eb:clear_selection W - clear the selection in widget W
  64. ######################################################################
  65.  
  66. proc j:eb:clear_selection { W args } {
  67.   $W select clear
  68. }
  69.  
  70. ######################################################################
  71. # j:eb:select_all W - select all text in widget W
  72. ######################################################################
  73.  
  74. proc j:eb:select_all { W args } {
  75.   $W select from 0
  76.   $W select to end
  77. }
  78.  
  79. ######################################################################
  80. # j:eb:is_bol W - return true if insert is at beginning of line
  81. #   from Achim Bonet <ach@.....>
  82. ######################################################################
  83.  
  84. proc j:eb:is_bol { W } {
  85.   return [expr {!([$W index insert])}]
  86. }
  87.  
  88. ######################################################################
  89. # j:eb:is_eol W - return true if insert is at end of line
  90. #   from Achim Bonet <ach@.....>
  91. ######################################################################
  92.  
  93. proc j:eb:is_eol { W } {
  94.   return [expr {!([$W index end]-[$W index insert])}]
  95. }
  96.  
  97. ######################################################################
  98. ###  GENERAL ENTRY ROUTINE (can be used as key or mouse binding)
  99. ######################################################################
  100.  
  101. # j:eb:paste_selection W - insert the X selection in an entry
  102. proc j:eb:paste_selection { W args } {
  103.   $W insert insert [string trim [j:selection_if_any] "\n\r"]
  104.   tk_entrySeeCaret $W
  105. }
  106.  
  107. ######################################################################
  108. ######################################################################
  109. ### ROUTINES TO SET UP ENTRY BINDINGS
  110.  
  111. # j:eb:key_bind W args - set up bindings to process keys
  112. proc j:eb:key_bind { W args } {
  113.   # get rid of a few default Tk bindings:
  114.   foreach binding {
  115.     <Any-Key> <Any-Key> <Control-Key-d> <Control-Key-h> <Control-Key-u>
  116.     <Control-Key-v> <Control-Key-w> <Control-Key> <Key-BackSpace>
  117.     <Key-Delete> <Key-Return> <Key> <Shift-Key>
  118.   } {
  119.     bind $W $binding {}
  120.   }
  121.   # and create null bindings for modifiers, so they don't trigger commands:
  122.   foreach binding {
  123.     <Shift_L> <Shift_R> <Control_L> <Control_R> <Caps_Lock>
  124.     <Shift_Lock> <Meta_L> <Meta_R> <Alt_L> <Alt_R>
  125.   } {
  126.     bind $W $binding { }
  127.   }
  128.   
  129.   bind $W <Key>            {j:ekb:process_key %W "" %K %A}
  130.   bind $W <Shift-Key>        {j:ekb:process_key %W "" %K %A}
  131.   bind $W <Control-Key>        {j:ekb:process_key %W Control %K %A}
  132.   
  133.   # Compose (Multi_key) key support:
  134.   bind $W <Multi_key>        { }
  135.   bind $W <Multi_key><Any-Key>    {j:ec:start_sequence %W %K %A}
  136.   bind $W <Multi_key><Any-Key><Any-Key> \
  137.                   {j:ec:finish_sequence %W %K %A}
  138.   bind $W <Multi_key><Any-KeyRelease><Any-Key> \
  139.                     {j:ec:start_sequence %W %K %A}
  140.   bind $W <Multi_key><Any-Key><Any-Key> \
  141.                   {j:ec:finish_sequence %W %K %A}
  142.   bind $W <Multi_key><Any-Key><Any-KeyRelease><Any-Key> \
  143.                   {j:ec:finish_sequence %W %K %A}
  144.   bind $W <Multi_key><Any-KeyRelease><Any-Key><Any-KeyRelease><Any-Key> \
  145.                   {j:ec:finish_sequence %W %K %A}
  146. }
  147.  
  148.